// ====== Computer Graphics Experiment #4 ======
// |      Line style using pixel mask          |
// |         and line width                    |  
// =============================================
//
// Requirement:
// (1) Implement a general Bresenham's Line Drawing Algorithm.
// (2) Implement solid, dashed, dotted and dot-dashed line styles 
//     using pixel mask. 
// (3) Implement keyboard function so that the user can switch 
//     line style by pressing a key.
// Only use GL_POINTS drawing mode. 
// Do not use OpenGL line drawing capability.
// Use bit shift statement in C: "<<" or ">>" 
// to implement pixel mask .

#include <windows.h>
#include <GL/glut.h>
#include <math.h>

#define PI 3.14159265359
int width, height;

int line_style=0;
unsigned int pixel_mask[]={0xffff, ..., ..., ...};
int line_width=1;

// Bresenham line algorithm with line style and line width
void MyLine(int xs, int ys, int xe, int ye)
{
	// Write your code here
}

// Initialization function
void init(void)
{
	glClearColor (0.0, 0.0, 0.0, 0.0);
}

// Display callback function
void display(void)
{
	int i, x0, y0, x, y;
	double a;

	glClear (GL_COLOR_BUFFER_BIT);

	x0=width/2;
	y0=height/2;

	glColor3f(1.0, 1.0, 1.0);

	// Draw lines
	for (i=0; i<360; i+=15)
	{
		a=(double)i/180.0*PI;
		x=0.45*width*cos(a);
		y=0.45*height*sin(a);
		if (i==0 || i==180) y=0;
		if (i==90 || i==270) x=0;
		MyLine(x0, y0, x0+x, y0+y);
	}

	glFlush();
}

// Reshape callback function
void reshape(int w, int h)
{
	// Record width and height of program window
	width=w;
	height=h;

	// Set clipping window and viewport equal to
	// view area of program window
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D (0.0, w, 0.0, h);
}

// Keyboard callback function
void keyboard(unsigned char key, int x, int y)
{
	switch (key) {
		case 27:
			exit(0);
		// Write your code for line style switching and line width switching
	}
}

// Main program entrance
int main(int argc, char* argv[])
{
	// Create window
	glutInit(&argc, argv);
	glutInitDisplayMode (GLUT_RGB);
	glutInitWindowSize(500, 500);
	glutCreateWindow("Lines");

	// Initialization
	init();

	// Define callback functions
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutDisplayFunc(display);

	// Main program loop. (Event loop)
	glutMainLoop();

	return 0;
}
